﻿using System.Data;
using Ue.Infrastructure.RepositoryFramework.Repository;
using Ue.Qcdz.Domain.SinglePages;

namespace Ue.Qcdz.Repositories.SinglePages
{
    public class SinglePageDataQueryWhereClause : IWhereClause
    {

        private ISinglePageDataQuery singlePageDataQuery;

        public SinglePageDataQueryWhereClause(ISinglePageDataQuery dataQuery)
        {
            this.singlePageDataQuery = dataQuery;
        }

        #region IWhereClause 成员

        public string Clause
        {
            get
            {
                string whereClause = "1=1";
                if (this.singlePageDataQuery.Status)
                    whereClause += string.Format(" and {0} = @{0}", SinglePageFactory.FieldNames.Status);
                if (!string.IsNullOrEmpty(this.singlePageDataQuery.CategoryId))
                    whereClause += string.Format(" and {0}='{1}'", SinglePageFactory.FieldNames.CategoryId, this.singlePageDataQuery.CategoryId);



                return whereClause;
            }
        }

        public System.Data.IDataParameter[] Parameters
        {
            get
            {
                return new IDataParameter[] {  
                    SqlServerDriver.Instance.BuildParameter(SinglePageFactory.FieldNames.Status, this.singlePageDataQuery.Status), 
                   // SqlServerDriver.Instance.BuildParameter(SinglePageFactory.FieldNames.CategoryId, this.singlePageDataQuery.CategoryId)                
                };
            }
        }

        #endregion
    }
}
